<?php
/**
 * 问答社区答案评论
*/
class Commwapcomment extends Base_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->load->model('commwap_model');
    }

    public function thumbup()
    {
        $cid = $this->input->input_stream('cid');
        $uid = $this->input->input_stream('uid');
        if (!isset($cid)||!is_numeric($cid)) $this->error('error: lack comment id');
        else $cid = (int)$cid;
        if (!isset($uid)||!is_numeric($uid)) $this->error('error: lack user id');
        else $uid = (int)$uid;
        $this->commwap_model->thumbup($cid,$uid);
        $this->success();
    }

    public function cancelThumbup()
    {
        $cid = $this->input->input_stream('cid');
        $uid = $this->input->input_stream('uid');
        if (!isset($cid)||!is_numeric($cid)) $this->error('error: lack comment id');
        else $cid = (int)$cid;
        if (!isset($uid)||!is_numeric($uid)) $this->error('error: lack user id');
        else $uid = (int)$uid;
        $this->commwap_model->cancelThumbup($cid,$uid);
        $this->success();
    }

    public function responseComm()
    {
        $cid = $this->input->input_stream('cid');
        $uid = $this->input->input_stream('uid');
        $comments = $this->input->input_stream('comment');
        if (!isset($cid)||!is_numeric($cid)) $this->error('error: lack comment id');
        else $cid = (int)$cid;
        if (!isset($uid)||!is_numeric($uid)) $this->error('error: lack user id');
        else $uid = (int)$uid;

        $data = array('uid'=>$uid,'commentid'=>$cid,'comments'=>$comments,'created'=>time());

        if ($this->commwap_model->responseComm($data)!==false) $this->success();
        else $this->error('系统错误');
    }

    public function getResponse()
    {
        $post = $this->input->post();
        if (!isset($post['cid'])||!is_numeric($post['cid'])) $this->error('error: lack comment id');
        else $cid = (int)$post['cid'];

        if (!isset($post['pagesize'])||!is_numeric($post['pagesize'])) $this->error('error: lack pagesize');
        else $limit = (int)$post['pagesize'];

        if (isset($post['page'])&&is_numeric($post['page'])) $offset = ((int)$post['page']-1)*$limit;
        else $offset = 0;


        $res = $this->commwap_model->getResponseBycid($cid,$offset,$limit);
        $this->success($res);
    }
}